/** 
 * 学习目标：练习-购物车加减
 * */
import React from "react";

export default class App extends React.Component {
    state = {
        count: 0,
    };

    render() {
        return (
            <div>
                <p>当前数值为：{this.state.count}</p>
                <hr />
                <button onClick={() => this.handleClick2(1)}>+1</button>
                <button onClick={() => this.handleClick(1)}>+1</button>
                <span>{this.state.count}</span>
                <button onClick={() => this.handleClick(-1)}>-1</button>
            </div>
        );
    }
    handleClick2 = num => {
        this.setState({
            count: this.state.count + num
        })
    }
    handleClick(num) {
        this.setState({
            count: this.state.count + num
        })
    }
}